package com.gxa.shop.servlet.order;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.gxa.shop.bean.dto.OrderDto;
import com.gxa.shop.bean.pojo.Product;
import com.gxa.shop.bean.vo.OrderVo;
import com.gxa.shop.commons.r.R;
import com.gxa.shop.service.order.OrderService;
import com.gxa.shop.service.order.impl.OrderServiceImpl;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;
import java.util.stream.Collectors;

@WebServlet(name = "UpdateOrderServlet",value = "/order/update")
public class UpdateOrderServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       BufferedReader bufferedReader=req.getReader();
        String  req_data=bufferedReader.readLine();
        OrderDto orderDto= JSONObject.parseObject(req_data, OrderDto.class);

        OrderService orderService=new OrderServiceImpl();
       int row= orderService.updateOrder(orderDto);
        R r;
        if (row>0){
            r=R.ok("更新成功");
        }else {
            r=R.error("更新失败");
        }
        String jsonResult=JSON.toJSONString(r);
        PrintWriter writer=resp.getWriter();
        writer.write(jsonResult);
        writer.flush();
        writer.close();
    }
}
